from sendapi.BaseSend import *
class SortMsg():
    def __init__(self,msg:str,programDict:dict):
        self.msg=msg
        self.programDict=programDict
        self.reminderKey=programDict["课程提醒"].keyWord
        self.accountKey=programDict["记账助手"].keyWord
        self.judge()
    def judge(self):
        for i in self.reminderKey:
            if i in self.msg :
                if self.programDict["课程提醒"].open:
                    reminder(i,self.msg,self.programDict['课程提醒']).judge()
                    break
                else:
                    FriendApi(2384945985,1656301062).sendWord('课程提醒：\n存在命令但处于关闭状态')
        for i in self.accountKey:
            if i in self.msg:
                if self.programDict["记账助手"].open:
                    account(i,self.msg,self.programDict['记账助手']).judge()
                    break
                else:
                    FriendApi(2384945985,1656301062).sendWord('记账助手：\n存在命令但处于关闭状态')



class reminder():
    def __init__(self,cmd,msg,obj):
        self.keyWord=['帮助-课程提醒']
        self.cmd=cmd
        self.msg=msg.replace(cmd,'').strip()
        self.obj=obj
    def judge(self):
        if self.cmd=="帮助-课程提醒":
            self.help()
    def help(self):
        pass

class account():
    def __init__(self,cmd:str,msg:str,obj):
        self.keyWord=['帮助-记账助手','记账','清单','退账','清账','更换账本','新建账本','账本']
        self.cmd=cmd
        self.msg=msg.replace(cmd,'').strip()
        self.obj=obj
    def judge(self):
        if self.cmd=="帮助-记账助手":
            self.help()
        elif self.cmd=="账本":
            self.showAccount()
        elif self.cmd=="记账":
            self.addItem(0)
        elif self.cmd=="收入":
            self.addItem(1)
        elif self.cmd=="清单":
            self.showItem()
        elif self.cmd=="退账":
            self.delItem()
        elif self.cmd=="清账":
            self.delAccount()
        elif self.cmd=="更换账本":
            self.changeAccount()
        elif self.cmd=="新建账本":
            self.addAccount()
    def help(self):
        self.obj.help()
    def showAccount(self):
        self.obj.showAccount()
    def addItem(self,cmd):
        option=self.msg.split(' ')[0]
        value=self.msg.split(' ')[1]
        self.obj.addItem(option,value,cmd)
    def showItem(self):
        self.obj.showItem()
    def delItem(self):
        self.obj.delItem(self.msg)
    def delAccount(self):
        self.obj.delAccount(self.msg)
    def changeAccount(self):
        self.obj.changeAccount(self.msg)
    def addAccount(self):
        self.obj.addAccount(self.msg)
